package com.kingwang.training.designpattern.exam;

import com.kingwang.training.designpattern.exam.bo.DepartmentContact;
import com.kingwang.training.designpattern.exam.bo.TaskIssueType;
import com.kingwang.training.designpattern.exam.config.EventRegister;
import com.kingwang.training.designpattern.exam.dao.TaskDao;
import com.kingwang.training.designpattern.exam.dto.AddTaskDTO;
import com.kingwang.training.designpattern.exam.service.TaskService;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.util.UUID;

@SpringBootApplication
public class ExamApplication implements ApplicationRunner {

    @Resource
    private EventRegister eventRegister;

    @Resource
    private TaskDao taskDao;

    @Resource
    private TaskService taskService;

    public static void main(String[] args) {
        SpringApplication.run(ExamApplication.class, args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        initData();

        this.eventRegister.init();

        AddTaskDTO addTaskDTO = new AddTaskDTO();

        addTaskDTO.setCreatorId(UUID.randomUUID());
        addTaskDTO.setIssueType(TaskIssueType.ISSUE_A);
        addTaskDTO.setProductId(UUID.randomUUID());
        addTaskDTO.setProductSerialNumber("1234567890123456");

        this.taskService.addTask(addTaskDTO);
    }

    private void initData() {
        this.taskDao.addDepartmentContact(new DepartmentContact(UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()));
    }
}
